{block name="resources"}

{/block}

{block name="main"}
        <ul class="nav nav-tabs v-nav-tabs add_tab1" role="tablist">
            <li role="presentation" class="active"><a href="#shop_info" aria-controls="shop_info" role="tab" data-toggle="tab" class="flex-auto-center">店铺信息</a></li>
            <li role="presentation"><a href="#shop_apply" aria-controls="shop_apply" role="tab" data-toggle="tab" class="flex-auto-center">注册信息</a></li>
        </ul>
        <!-- page -->
        <form class="form-horizontal pt-15 form-validate widthFixedForm">
            <div id="myTabContent" class="tab-content">
                <div role="tabpanel" class="tab-pane fade in active tab-1" id="shop_info" >
                    <div class="form-group">
                        <label class="col-md-2 control-label"><span class="text-bright">*</span>店铺名称</label>
                        <div class="col-md-5">
                            <input type="text" class="form-control" value="{$info['shop_name']}" id="shop_name" placeholder="请输入店铺名称" name="shop_name" required title="店铺名称不能为空">
                        </div>
                    </div>
                    {if !$info['shop_id'] && $info['shop_id']!='0'}
                    <div class="form-group">
                        <label class="col-md-2 control-label"><span class="text-bright">*</span>手机号码</label>
                        <div class="col-md-5">
                            <input type="number" class="form-control" id="user_account" placeholder="请输入手机号码" name="user_account" required isMobile="true">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label"><span class="text-bright">*</span>密码</label>
                        <div class="col-md-5">
                            <input type="password" class="form-control" id="user_pwd" name="user_pwd" placeholder="请输入会员密码" required title="会员密码不能为空" autocomplete="new-password" maxlength="20" >
                        </div>
                    </div>
                    {/if}
                    {if $info['shop_id']}
                    <div class="form-group">
                        <label class="col-md-2 control-label"><span class="text-bright">*</span>手机号码</label>
                        <div class="col-md-5">
                            <input type="number" class="form-control" value="{$info['user_tel']}"  disabled>
                        </div>
                    </div>
                    {/if}
                    <div class="form-group">
                        <label class="col-md-2 control-label"><span class="text-bright">*</span>所属分类</label>
                        <div class="col-md-5">
                            <select id="shop_group_id" name="shop_group_id" class="form-control" required title="请选择分类">
                                <option value="">请选择</option>
                                {foreach name="group_list" item="vg"}
                                <option value="{$vg['shop_group_id']}" {if condition="$info['shop_group_id'] eq $vg['shop_group_id']"} selected {/if}>{$vg['group_name']}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    {if $info['shop_id']!='0'}
                    <div class="form-group">
                        <label class="col-md-2 control-label"><span class="text-bright">*</span>店铺版本</label>
                        <div class="col-md-5">
                            <select id="shop_type" name="shop_type" class="form-control" required title="请选择店铺版本">
                                <option value="">请选择</option>
                                {foreach name="type_list" item="vt"} 
                                <option value="{$vt['instance_typeid']}" {if condition="$info['shop_type'] eq $vt['instance_typeid']"} selected {/if}>{$vt['type_name']}</option>
                                {/foreach}
                            </select>
                        </div>
                        <!--                <div class="col-md-5 help-block">
                                            没有店铺版本？去<a href="" target="_blank" class="text-primary">新建</a>，新建完点刷新
                                        </div>-->
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">平台抽成</label>
                        <div class="col-md-5">
                            <div class="input-group">
                                <input type="number" class="form-control" min="0" max="100" id="shop_platform_commission_rate" name="shop_platform_commission_rate" value="{$info['shop_platform_commission_rate']}">
                                <div class="input-group-addon">%</div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">保证金</label>
                        <div class="col-md-5">
                            <input type="text" class="form-control" id="margin" value="{$info['margin']}" name="margin">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">商家编码</label>
                        <div class="col-md-5">
                            <input type="text" class="form-control" id="barcode" value="{$info['barcode']}" name="barcode">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">店铺状态</label>
                        <div class="col-md-5">
                            <div class="switch-inline">
                                <input type="checkbox" id="shop_state" name="shop_state" {if condition="$info['shop_state'] eq 1"} checked {/if}>
                                       <label for="shop_state" class=""></label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">审核入驻店商品</label>
                        <div class="col-md-5">
                            <div class="switch-inline">
                                <input type="checkbox" id="shop_audit" name="shop_audit" {if condition="$info['shop_audit'] eq 1"} checked {/if}>
                                       <label for="shop_audit" class=""></label>
                            </div>
                            <p class="help-block">开启后该商家发布的商品都需要平台审核才能上架</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">排序</label>
                        <div class="col-md-5">
                            <input type="number" class="form-control" id='shop_sort' value="{$info['shop_sort']}" name="sort">
                        </div>
                    </div>
                    
                    {/if}
                </div>
                <div role="tabpanel" class="tab-pane fade in tab-2" id="shop_apply">
                    <div class="screen-title"><span class="text">企业或个人信息</span></div>
                     <div class="form-group">
                        <label class="col-md-2 control-label">申请类型</label>
                        <div class="col-md-5">
                            <label class="radio-inline">
                                <input type="radio" name="apply_type" value="1" {if $shop_info['apply_type']==1} checked="checked" {/if}> 个人
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="apply_type" value="2" {if $shop_info['apply_type']==2 || !$shop_info['apply_type']} checked="checked" {/if}> 企业
                            </label>
                        </div>
                    </div>
                    <div class="form-group J-company">
                        <label class="col-md-2 control-label">公司名称</label>
                        <div class="col-md-5">
                            <input type="text" class="form-control" id="company_name" name="company_name" placeholder="请输入公司名称" value="{$shop_info['company_name']}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="address" class="col-md-2 control-label fw J-per">联系地址</label>
                        <label for="address" class="col-md-2 control-label fw J-company">公司所在地</label>
                        <div class="col-md-5">
                            <div class="area-form-group">
                                <select name="province" id="selProvinces"  class="form-control getProvince">
                                        <option value="-1">请选择省...</option>
                                </select>
                                <select name="city" id="selCities"  class="form-control getSelCity">
                                        <option value="-1">请选择市...</option>
                                </select>
                                <select name="district" id="selDistricts" class="form-control">
                                        <option value="-1">请选择区...</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label J-per">详细地址</label>
                        <label class="col-md-2 control-label  J-company">公司详细地址</label>
                        <div class="col-md-5">
                            <input type="text" class="form-control" id="company_address_detail" name="company_address_detail" placeholder="请输入公司详细地址" value="{$shop_info['company_address_detail']}">
                        </div>
                    </div>
                     <div class="form-group J-company">
                        <label class="col-md-2 control-label">公司类型</label>
                        <div class="col-md-5">
                            <select id="company_type" name="company_type" class="form-control">
                                <option value="私企" {if condition="$shop_info['company_type'] eq '私企'"} selected {/if}>私企</option>
                                <option value="个体" {if condition="$shop_info['company_type'] eq '个体'"} selected {/if}>个体</option>
                                <option value="外企" {if condition="$shop_info['company_type'] eq '外企'"} selected {/if}>外企</option>
                                <option value="中外合资" {if condition="$shop_info['company_type'] eq '中外合资'"} selected {/if}>中外合资</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group J-company">
                        <label class="col-md-2 control-label">公司电话</label>
                        <div class="col-md-5">
                            <input type="text" class="form-control" id="company_phone" name="company_phone" placeholder="请输入公司电话" value="{$shop_info['company_phone']}">
                        </div>
                    </div>
                    <div class="form-group J-company">
                        <label class="col-md-2 control-label">员工总数</label>
                        <div class="col-md-5">
                            <input type="number" class="form-control" min='0' id="company_employee_count" name="company_employee_count" placeholder="请输入员工总数" value="{$shop_info['company_employee_count']}">
                        </div>
                    </div>
                    <div class="form-group J-company">
                        <label class="col-md-2 control-label">注册资金（万元）</label>
                        <div class="col-md-5">
                            <input type="number" class="form-control" min='0' id="company_registered_capital" name="company_registered_capital" placeholder="请输入注册资金" value="{$shop_info['company_registered_capital']}">
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label class="col-md-2 control-label">联系人姓名</label>
                        <div class="col-md-5">
                            <input type="text" class="form-control" id="contacts_name" name="contacts_name" placeholder="请输入联系人姓名" value="{$shop_info['contacts_name']}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">联系人电话</label>
                        <div class="col-md-5">
                            <input type="text" class="form-control" id="contacts_phone" name="contacts_phone" placeholder="请输入联系人电话" value="{$shop_info['contacts_phone']}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">电子邮箱</label>
                        <div class="col-md-5">
                            <input type="text" class="form-control" id="contacts_email" name="contacts_email" placeholder="请输入电子邮箱" value="{$shop_info['contacts_email']}">
                        </div>
                    </div>
                    <div class="screen-title  J-company"><span class="text">营业执照信息（副本）</span></div>
                    <div class="form-group J-company">
                        <label class="col-md-2 control-label">营业执照号</label>
                        <div class="col-md-5">
                            <input type="text" class="form-control" id="business_licence_number" name="business_licence_number" placeholder="请输入营业执照号" value="{$shop_info['business_licence_number']}">
                        </div>
                    </div>
                    <div class="form-group J-company">
                        <label class="col-md-2 control-label">法定经营范围</label>
                        <div class="col-md-5">
                            <textarea class="form-control" id="business_sphere" name="business_sphere">{$shop_info['business_sphere']}</textarea>
                        </div>
                    </div>
                    <div class="form-group J-company">
                        <label class="col-md-2 control-label">营业执照照片</label>
                        <div class="col-md-5 picture-list" id='business_licence_number_electronic'>
                            {if condition="$shop_info['business_licence_number_electronic'] eq ''"}
                            <a href="javascript:;" class="plus-box" data-toggle="singlePicture"><i class="icon icon-plus"></i></a>
                            {else}
                            <a href="javascript:;" class="close-box"><i class="icon icon-danger" title="删除"></i><img src="{:__IMG($shop_info['business_licence_number_electronic'])}"></a>
                            {/if}
                        </div>
                    </div>
                    <div class="screen-title"><span class="text">身份证信息</span></div>
                    <div class="form-group">
                        <label class="col-md-2 control-label J-per">身份证号码</label>
                        <label class="col-md-2 control-label J-company">法人身份证号码</label>
                        <div class="col-md-5">
                            <input type="text" class="form-control" id="contacts_card_no" name="contacts_card_no" placeholder="请输入身份证号码" value="{$shop_info['contacts_card_no']}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label J-per">手持身份证照片</label>
                        <label class="col-md-2 control-label J-company">法人手持身份证照片</label>
                        <div class="col-md-5 picture-list" id='contacts_card_electronic_1'>
                            {if condition="$shop_info['contacts_card_electronic_1'] eq ''"}
                            <a href="javascript:;" class="plus-box" data-toggle="singlePicture"><i class="icon icon-plus"></i></a>
                            {else}
                            <a href="javascript:;" class="close-box"><i class="icon icon-danger" title="删除"></i><img src="{$shop_info['contacts_card_electronic_1']}"></a>
                            {/if}
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label J-per">身份证正面</label>
                        <label class="col-md-2 control-label J-company">法人身份证正面</label>
                        <div class="col-md-5 picture-list" id='contacts_card_electronic_2'>
                            {if condition="$shop_info['contacts_card_electronic_2'] eq ''"}
                            <a href="javascript:;" class="plus-box" data-toggle="singlePicture"><i class="icon icon-plus"></i></a>
                            {else}
                            <a href="javascript:;" class="close-box"><i class="icon icon-danger" title="删除"></i><img src="{$shop_info['contacts_card_electronic_2']}"></a>
                            {/if}
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label J-per">身份证反面</label>
                        <label class="col-md-2 control-label J-company">法人身份证反面</label>
                        <div class="col-md-5 picture-list" id='contacts_card_electronic_3'>
                            {if condition="$shop_info['contacts_card_electronic_3'] eq ''"}
                            <a href="javascript:;" class="plus-box" data-toggle="singlePicture"><i class="icon icon-plus"></i></a>
                            {else}
                            <a href="javascript:;" class="close-box"><i class="icon icon-danger" title="删除"></i><img src="{$shop_info['contacts_card_electronic_3']}"></a>
                            {/if}
                        </div>
                    </div>
                </div>
                <div class="form-group"></div>
                <div class="form-group">
                    <label class="col-md-2 control-label"></label>
                    <div class="col-md-8">
                        <button class="btn btn-primary J-add" type="submit">{if $info}保存{else}添加{/if}</button>
                        <a href="javascript:history.go(-1);" class="btn btn-default">返回</a>
                    </div>
                </div>
            </div>
            <input type="hidden" id="shop_id" name="shop_id" value="{$info['shop_id']}">
            <input type="hidden" id="pid" name="pid" value="{$shop_info['company_province_id']}">
            <input type="hidden" id="cid" name="cid" value="{$shop_info['company_city_id']}">
            <input type="hidden" id="aid" name="aid" value="{$shop_info['company_district_id']}">
        </form>

        <!-- page end -->
{/block}
{block name="script"}
<script>
    require(['util'], function (util) {
         $(document).ready(function(){
            var apply_type = $('input[name=apply_type]:checked').val();
            if(apply_type==1){
                $('.J-per').show();
                $('.J-company').hide();
            }else{
                $('.J-per').hide();
                $('.J-company').show();
            }
        });
        var pid=0,cid=0,aid=0;
        initProvince("#selProvinces");
        function initProvince(obj){
            pid = $('#pid').val();
            $.ajax({
                type : "post",
                url : "{$getProvinceUrl}",
                dataType : "json",
                success : function(data) {
                    if (data != null && data.length > 0) {
                        var str = "";
                        for (var i = 0; i < data.length; i++) {
                            if(pid == data[i].province_id){
                                str += '<option selected value="'+data[i].province_id+'">'+data[i].province_name+'</option>';
                            }else{
                                str += '<option value="'+data[i].province_id+'">'+data[i].province_name+'</option>';
                            }
                        }
                        $(obj).append(str);
                    }
                }
            });
        }
        getProvince();
        //选择省份弹出市区
        $('.getProvince').on('change', function () {
            var id = $('#selProvinces').val();
            if(id==-1){
                id = pid;
            }
            cid = $('#cid').val();
            $.ajax({
                type : "post",
                url :"{$getCityUrl}",
                dataType : "json",
                data : {
                    "province_id" : id
                },
                success : function(data) {
                    if (data != null && data.length > 0) {
                        var str = "<option value='-1'>请选择市</option>";
                        for (var i = 0; i < data.length; i++) {
                            if(cid == data[i].city_id) {
                                str += '<option selected value="' + data[i].city_id + '">' + data[i].city_name + '</option>';
                            }else{
                                str += '<option  value="' + data[i].city_id + '">' + data[i].city_name + '</option>';
                            }
                        }
                        $('#selCities').html(str);
                    }
                }
            });
        })
        function getProvince() {
            var id = $('#selProvinces').val();
            if(id==-1){
                id = pid;
            }
            cid = $('#cid').val();
            $.ajax({
                type : "post",
                url :"{$getCityUrl}",
                dataType : "json",
                data : {
                    "province_id" : id
                },
                success : function(data) {
                    if (data != null && data.length > 0) {
                        var str = "<option value='-1'>请选择市</option>";
                        for (var i = 0; i < data.length; i++) {
                            if(cid == data[i].city_id) {
                                str += '<option selected value="' + data[i].city_id + '">' + data[i].city_name + '</option>';
                            }else{
                                str += '<option  value="' + data[i].city_id + '">' + data[i].city_name + '</option>';
                            }
                        }
                        $('#selCities').html(str);
                    }
                }
            });
        };
        getSelCity();
        //选择市区弹出区域
        $('.getSelCity').on('change', function () {
            var id = $('#selCities').val();
            aid = $('#aid').val();
            if(id==-1){
                id = cid;
            }
            $.ajax({
                type : "post",
                url : "{$getDistrictUrl}",
                dataType : "json",
                data : {
                    "city_id" : id
                },
                success : function(data) {
                    if (data != null && data.length > 0) {
                        var str = "<option value='-1'>请选择区</option>";
                        for (var i = 0; i < data.length; i++) {
                            if(aid==data[i].district_id){
                                str += '<option selected value="'+data[i].district_id+'">'+data[i].district_name+'</option>';
                            }else{
                                str += '<option value="'+data[i].district_id+'">'+data[i].district_name+'</option>';
                            }

                        }
                        $('#selDistricts').html(str);
                    }
                }
            });
        })
        function getSelCity() {
            var id = $('#selCities').val();
            aid = $('#aid').val();
            if(id==-1){
                id = cid;
            }
            $.ajax({
                type : "post",
                url : "{$getDistrictUrl}",
                dataType : "json",
                data : {
                    "city_id" : id
                },
                success : function(data) {
                    if (data != null && data.length > 0) {
                        var str = "<option value='-1'>请选择区</option>";
                        for (var i = 0; i < data.length; i++) {
                            if(aid==data[i].district_id){
                                str += '<option selected value="'+data[i].district_id+'">'+data[i].district_name+'</option>';
                            }else{
                                str += '<option value="'+data[i].district_id+'">'+data[i].district_name+'</option>';
                            }

                        }
                        $('#selDistricts').html(str);
                    }
                }
            });
        }
        
        $('input[name=apply_type]').change(function(){
            if($(this).val()==='1'){
                $('.J-per').show();
                $('.J-company').hide();
            }else{
                $('.J-per').hide();
                $('.J-company').show();
            }
        });
       
        //添加店铺
        util.validate($('.form-validate'), function (form) {
            var shop_id = $("#shop_id").val();
            var apply_type = $('input[name=apply_type]:checked').val(); 
            var user_account = $("#user_account").val();
            var user_pwd = $("#user_pwd").val();
            var shop_name = $("#shop_name").val();
            var shop_group_id = $("#shop_group_id").val();
            var shop_type = $("#shop_type").val();
            var shop_platform_commission_rate = $("#shop_platform_commission_rate").val();
            var margin = $("#margin").val();
            var shop_sort = $("#shop_sort").val();
            var shop_state = 0;
            var shop_audit = 0;
            if($("#shop_state").is(":checked")){
                shop_state = 1;
            }
            if($("#shop_audit").is(":checked")){
                shop_audit = 1;
            }
            if(!shop_id){
                if(user_pwd.length<6){
                    util.message("密码长度为6-20个字符","danger");
                    $("#user_pwd").focus();
                    return false;
                }
            }
            var company_name = $("#company_name").val();
            var company_province_id = $("#selProvinces").val();
            var company_city_id = $("#selCities").val();
            var company_district_id = $("#selDistricts").val();
            var company_type = $("#company_type").val();
            var company_address_detail = $("#company_address_detail").val();
            var company_phone = $("#company_phone").val();
            var company_employee_count = $("#company_employee_count").val();
            var company_registered_capital = $("#company_registered_capital").val();
            var contacts_name = $("#contacts_name").val();
            var contacts_phone = $("#contacts_phone").val();
            var contacts_email = $("#contacts_email").val();
            var barcode = $("#barcode").val();
            //营业执照信息（副本）
            var business_licence_number = $("#business_licence_number").val();
            var business_sphere = $("#business_sphere").val();
            var business_licence_number_electronic = $("#business_licence_number_electronic").find('img').attr('src');
            var contacts_card_no = $("#contacts_card_no").val();
            var contacts_card_electronic_1 = $("#contacts_card_electronic_1").find('img').attr('src');
            var contacts_card_electronic_2 = $("#contacts_card_electronic_2").find('img').attr('src');
            var contacts_card_electronic_3 = $("#contacts_card_electronic_3").find('img').attr('src');
            
            $.ajax({
                type: "post",
                url: "{$addPlatformShopUrl}",
                data: {
                    'shop_id' : shop_id,
                    'shop_name': shop_name,
                    'apply_type': apply_type,
                    'shop_group_id': shop_group_id,
                    'shop_type': shop_type,
                    'user_account': user_account,
                    'user_pwd': user_pwd,
                    'shop_platform_commission_rate': shop_platform_commission_rate,
                    'margin': margin,
                    'shop_sort': shop_sort,
                    'shop_state': shop_state,
                    'shop_audit': shop_audit,
                    'company_name': company_name,
                    'company_type': company_type,
                    'company_province_id': company_province_id,
                    'company_city_id': company_city_id,
                    'company_district_id': company_district_id,
                    'company_address_detail': company_address_detail,
                    'company_phone': company_phone,
                    'company_employee_count': company_employee_count,
                    'company_registered_capital': company_registered_capital,
                    'contacts_name': contacts_name,
                    'contacts_phone': contacts_phone,
                    'contacts_email': contacts_email,
                    'barcode': barcode,
                    'business_licence_number': business_licence_number,
                    'business_sphere': business_sphere,
                    'business_licence_number_electronic': business_licence_number_electronic,
                    'contacts_card_no': contacts_card_no,
                    'contacts_card_electronic_1': contacts_card_electronic_1,
                    'contacts_card_electronic_2': contacts_card_electronic_2,
                    'contacts_card_electronic_3': contacts_card_electronic_3,
                    'website_id': '{$website_id}'
                    
                },
                async: true,
                success: function (data) {
                    if (data["code"] > 0) {
                        util.message('操作成功', 'success', "{:__URL('ADDONS_MAINshopList')}");
                    }else if(data["code"]==-3) {
                        util.message('该手机已经是商城用户', 'danger');
                    } else {
                        util.message(data["message"], 'danger');
                    }
                }
            });
        });
    });
</script>
{/block}